# 业务层View：实现登录、注册
import orm


def login():
    path = r'users.json'
    tag = 0
    name = input('请输入登录的用户名：')
    pwd = input('请输入登录的密码：')
    user_list = orm.read_data(path)
    for user in user_list:
        if name == user['username'] and pwd == user['password']:
            tag = 1
            break
    return tag


def register():
    path = r'users.json'
    name = input('请输入注册的用户名：')
    pwd = input('请输入注册的密码：')
    new_user = {'username': name, 'password': pwd}
    user_list = orm.read_data(path)
    user_list.append(new_user)
    orm.write_data(user_list, path)


if __name__ == '__main__':
    # 测试一下login()
    print(login())

    # # 测试一下register()
    # register()
